package cn.changshengjue.dakong.utils;

import java.io.File;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;

import cn.changshengjue.dakong.main;

//yml操作类
public class YmlUtil {
	public File getFile(String ymlFileName) {
		File ymlFile = new File(main.getInstance().getDataFolder(), ymlFileName);
		if (!ymlFile.exists()) {
			if (!ymlFile.getParentFile().exists())
				ymlFile.getParentFile().mkdirs();
			try {
				ymlFile.createNewFile();
			} catch (Exception e) {
			}
		}
		return ymlFile;
	}

	public FileConfiguration getFileMine(File ymlFile) {
		FileConfiguration fileMine = ymlFile.exists() ? YamlConfiguration.loadConfiguration(ymlFile)
				: new YamlConfiguration();
		return fileMine;
	}

	public void saveFiles(File file, FileConfiguration fileMine) {
		try {
			fileMine.save(file);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
